#!/bin/bash

# Usage:
# ./tag.sh
# Note that all paths are RELATIVE, which implies that if this script is 
# moved to another directory in the future, all paths MUST be changed.

version=`grep '"version"' < src/manifest.json | \
	sed 's/.*"\([0-9.]*\)".*/\1/'`
tag=../tags/$version

./manifest_filter.pl --17 src/manifest.json > /dev/null

if [[ -d $tag ]]; then
	echo ERROR: Branch of the current version already exists. Please update \"version\" in manifest.json.
	exit 1
fi

read -p "Are you sure to tag version $version? [Y,n]"

if [[ -z $REPLY || $REPLY == "y" || $REPLY == "Y" ]]; then
	svn cp -q ./src $tag
	#read -p "Are you sure to commit the change? [Y,n]"
	#if [[ -z $REPLY || $REPLY == "y" || $REPLY == "Y" ]]; then
	#	svn commit -m "Branching for version $version" ../
	#fi
	echo Tagged version $version into $tag. Please commit the change.
fi

